<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el);

      this.chart.setOption({
        series: [
          {
            type: "gauge",
            startAngle: -270,
            endAngle: 90,
            pointer: {
              show: false,
            },
            progress: {
              show: true,
              overlap: false,
              roundCap: false,
              clip: true,
              itemStyle: {
                borderWidth: 0,
                // color:'rgb(255,255,255)'
              },
            },
            axisLine: {
              lineStyle: {
                width: 25,
              },
            },
            splitLine: {
              show: false,
              distance: 0,
              length: 10,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: false,
              distance: 50,
            },
            data: [
              {
                value: 99,
                name: "活动完成率",
                title: {
                  offsetCenter: ["0%", "-10%"],
                },
                detail: {
                  valueAnimation: true,
                  offsetCenter: ["0%", "20%"],
                },
              },
            ],
            title: {
              fontSize: 16,
            },
            detail: {
              fontSize: 18,
              color: "#000",
              formatter: "{value}%",
            },
          },
        ],
      });
    },
  },
};
</script>
